﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PolarSonicLink
{
    public partial class CyclogOptions : Form
    {
        public CyclogOptions(CyclogsUserValues cyclogsUserValues)
        {
            InitializeComponent();

            m_cyclogsUserValues = cyclogsUserValues;
        }

        private void CyclogOptions_Load(object sender, EventArgs e)
        {
            textBoxUserName.Text = m_cyclogsUserValues.UserName;

            foreach ( string thisRoute in m_cyclogsUserValues.Routes )
            {
                listBoxRoutes.Items.Add(thisRoute);
            }

            foreach ( string thisBike in m_cyclogsUserValues.Bikes )
            {
                listBoxBikes.Items.Add(thisBike);
            }

            foreach ( string thisRideType in m_cyclogsUserValues.RideTypes )
            {
                listBoxRideTypes.Items.Add(thisRideType);
            }
        }

        private void buttonRouteAdd_Click(object sender, EventArgs e)
        {
            StringEntry stringEntry = new StringEntry();

            if ( stringEntry.ShowDialog() == DialogResult.OK )
            {
                listBoxRoutes.Items.Add(stringEntry.enteredString);
            }
        }

        private void buttonRouteRemove_Click(object sender, EventArgs e)
        {
            if ( listBoxRoutes.SelectedIndex > -1 )
            {
                listBoxRoutes.Items.RemoveAt(listBoxRoutes.SelectedIndex);
            }
        }

        private void buttonBikeAdd_Click(object sender, EventArgs e)
        {
            StringEntry stringEntry = new StringEntry();

            if ( stringEntry.ShowDialog() == DialogResult.OK )
            {
                listBoxBikes.Items.Add(stringEntry.enteredString);
            }
        }

        private void buttonBikeRemove_Click(object sender, EventArgs e)
        {
            if ( listBoxBikes.SelectedIndex > -1 )
            {
                listBoxBikes.Items.RemoveAt(listBoxBikes.SelectedIndex);
            }
        }

        private void buttonRideTypeAdd_Click(object sender, EventArgs e)
        {
            StringEntry stringEntry = new StringEntry();

            if ( stringEntry.ShowDialog() == DialogResult.OK )
            {
                listBoxRideTypes.Items.Add(stringEntry.enteredString);
            }
        }

        private void buttonRideTypeRemove_Click(object sender, EventArgs e)
        {
            if ( listBoxRideTypes.SelectedIndex > -1 )
            {
                listBoxRideTypes.Items.RemoveAt(listBoxRideTypes.SelectedIndex);
            }
        }

        public CyclogsUserValues m_cyclogsUserValues;

        private void buttonSave_Click(object sender, EventArgs e)
        {
            CyclogsUserValues newValues = new CyclogsUserValues();

            newValues.UserName = textBoxUserName.Text;

            foreach (string thisItem in listBoxRoutes.Items)
            {
                newValues.Routes.Add(thisItem);
            }

            foreach ( string thisItem in listBoxBikes.Items )
            {
                newValues.Bikes.Add(thisItem);
            }

            foreach ( string thisItem in listBoxRideTypes.Items )
            {
                newValues.RideTypes.Add(thisItem);
            }

            m_cyclogsUserValues = newValues;
        }
    }
}
